package com.finalist.job;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.finalist.entity.Product;
import com.finalist.service.ProductService;


@Component
@Lazy(value = false)
public class ProductTask
{
	@Resource(name = "productServiceImpl")
	private ProductService productService;

    @Scheduled(cron = "0 0 3 * * ?")
	//@Scheduled(cron = "0 */1 * * * ?")
    public void updatePhoneNumber()
    {
        
    	List<Product> products=productService.findExpireProduct();
    	System.out.println(products.size());
    	if(products!=null&&products.size()!=0){
    		for(Product product:products){
    			product.setIsMarketable(false);
    			try {
					productService.update(product);
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
    		}
    	}
    }
}
